<?php


namespace app\cms\model;


use app\cms\community\lib\QueryModel;

class resourcesModel extends QueryModel
{

    protected $table = "resources_table";

    public static function getResources(string $resourcesIds = '')
    {
        $res = static::whereIn('resources_id', $resourcesIds) -> hidden(['resources_pwd']) -> select() -> toArray();
        if ($res) return message() -> success('查询成功', $res);
        return message() -> nodata('暂无资源数据');
    }

    public static function saveResources(array $resources)
    {
        $save = static::insertAll($resources);
        return $save ? message() -> success('保存成功', $resources)
            : message() -> update_failed('保存失败');
    }

    public static function deleteResources(string $resourcesIds = '')
    {
        $files = static::getResources($resourcesIds) -> data;
        foreach ($files['items'] as $file) {
            unlink($file['resources_path']);
        }
        static::whereIn('resources_id', $resourcesIds) -> delete();
        return message() -> success('删除成功');
    }

}